package com.shop.car.controller;

import com.shop.car.domain.ShopCarDetails;
import com.shop.car.service.ShopCarService;
import com.shop.common.core.domain.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author：作者姓名
 * @Package：com.shop.car.controller
 * @Project：Shop
 * @name：ShopCarController
 * @Date：2024/6/21 18:26
 */
@RestController
@RequestMapping("/shopCar")
public class ShopCarController {
    @Autowired
    private ShopCarService shopCarService;

    /**
     * 我的购物车
     */
    @GetMapping("findShopCar")
    public Result<List<ShopCarDetails>> findShopCar() {
        List<ShopCarDetails> shopCar = shopCarService.findShopCar();
        if (shopCar == null) {
        }
        return Result.success(shopCar);
    }

    @PostMapping("/insertShopCar/{skuId}/{detailsCount}")
    public Result insertShopCar(@PathVariable("skuId") Long skuId, @PathVariable("detailsCount") Long detailsCount) {
        shopCarService.insertShopCar(skuId, detailsCount);
        return Result.success();
    }

    @PostMapping("/updateShopCar")
    public Result updateShopCar(@RequestParam("skuId") Long skuId, @RequestParam("detailsCount") Long detailsCount) {
        shopCarService.updateShopCar(skuId, detailsCount);
        return Result.success();
    }

    @PostMapping("/deleteShopCar")
    public Result deleteShopCar(@RequestParam("carId") Long carId) {
        shopCarService.deleteShopCar(carId);

        System.out.println("xxx");
        return Result.success();
    }
    @GetMapping("details")
    public Result<ShopCarDetails> findShopCarDetails(@RequestParam("detailsId") Long detailsId) {
        ShopCarDetails shopCarDetails = shopCarService.FindDetailsBySkuIdAndDetailsId(detailsId);
        return Result.success(shopCarDetails);
    }

    @PostMapping("findByDetailsId")
    public Result<List<ShopCarDetails>> findByDetailsId(@RequestBody Long[] ids) {
        List<ShopCarDetails> shopCar = shopCarService.findByDetailsId(ids);
        return Result.success(shopCar);
    }
}
